# /*
#  * @Descripttion: 
#  * @version: V1.0.0
#  * @Author: Maverick
#  * @Date: 2025-03-15 20:18:02
#  * @LastEditors: Maverick
#  * @LastEditTime: 2025-03-15 20:21:12
#  */
SHELL=/bin/bash
CC=g++
CURRENT_PATH:=$(shell pwd)
INC_DIR:=$(CURRENT_PATH)/include
SRC_DIR:=$(CURRENT_PATH)/src
TEST_DIR:=$(CURRENT_PATH)/test
BUILD_DIR:=$(CURRENT_PATH)/build



CGTESTFLAGS= -g  -Werror -std=c++14 -Wall -O2 -I/usr/local/include \
												-I$(INC_DIR)
CGTESTLDFLAGS= -g -Werror -std=c++14 -Wall -O2 \
								-L/usr/local/lib \
								-lgtest \
								-lgtest_main \
								-lpthread

CFLAGS= -g \
		-Wall \
		-O2 \
		-I$(INC_DIR)

BIN:=sqlistbin
BIN_TEST:=sqlisttest
TAG:="[xiaobisoftware]"

export CC CFLAGS BIN BIN_TEST SRC_DIR BUILD_DIR INC_DIR TEST_DIR TAG CGTESTFLAGS CGTESTLDFLAGS


RESET = "\e[0m"
BLACK = "\e[30;1m"
RED  =  "\e[31;1m"
GREEN = "\e[32;1m"
YELLOW = "\e[33;1m"
BLUE  = "\e[34;1m"
PURPLE = "\e[35;1m"
CYAN  = "\e[36;1m"
WHITE = "\e[37;1m"
ALL:="[all test]"

export RESET BLACK RED GREEN YELLOW BLUE PURPLE CYAN WHITE SHELL
.PHONY:all
all:
	$(eval START_TIME := $(shell date +%s%N))
	@echo "$(TAG) $(ALL) begin at $(shell date)\n"
	@echo "$(TAG) BUILD DIR IS $(BUILD_DIR)\n"
	sudo mkdir -p $(BUILD_DIR)
	make -C $(SRC_DIR) all
	make -C $(TEST_DIR) all
	@echo -e $(GREEN)" $(TAG) $(ALL) copy over $(shell date)"
	$(eval END_TIME := $(shell date +%s%N))
	$(eval ELAPSED_TIME := $(shell expr $(END_TIME) - $(START_TIME)))
	@echo -e $(PURPLE)"$(TAG) 编译总耗时 :[$(ELAPSED_TIME) ]纳秒  [$$(( $(ELAPSED_TIME) / 1000 ))]微秒 [$$(( $(ELAPSED_TIME) / 1000000 )) ]毫秒  "$(RESET)
	@echo -e $(GREEN)"$(TAG) $(ALL) over at $(shell date)"


.PHONY:clean
clean:
	@make -C $(SRC_DIR) clean
	@make -C $(TEST_DIR) clean
	sudo rm -rf $(BUILD_DIR)
	@echo "$(TAG) [clean] over at $(shell date)\n"